package com.demo.service;

import com.demo.dao.AccountDao;

public class AccountServiceImpl implements AccountService {
    
    private AccountDao accountDao;
    
    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }
    
    @Override
    public void transfer(Integer fromId, Integer toId, Double amount) {
        Double fromBalance = accountDao.queryBalance(fromId);
        
        if (fromBalance < amount) {
            throw new RuntimeException("余额不足，转账失败");
        }
        
        accountDao.updateBalance(fromId, fromBalance - amount);
        Double toBalance = accountDao.queryBalance(toId);
        accountDao.updateBalance(toId, toBalance + amount);
    }
} 